package main.testers;

import java.io.File;
import java.util.List;

import modules.dimensioning.CoverageInterface;
import modules.dimensioning.GeneticSearch;
import modules.dimensioning.LegislationInterface;
import modules.dimensioning.solution.Solution;
import modules.legislation.LegislationAdapter;
import modules.pathloss.CoverageAdapter;

import org.geotools.geometry.jts.JTSFactoryFinder;

import tools.Log;
import tools.gis.antennaReader.AntennaSite;
import tools.gis.antennaReader.AntennaSiteReader;
import tools.settings.SettingsAdapter;

import com.vividsolutions.jts.geom.Polygon;
import com.vividsolutions.jts.io.WKTReader;

import datatypes.Antenna;
import modules.legislation.PathlossInterface;
import modules.legislation.law.Belgium;
import modules.legislation.law.LawInterface;
import modules.pathloss.PathLossAdapter;

public class LegislationDemo {

	public static void main(String[] args){
		new LegislationDemo();
	}
	

	Polygon area;
	int generations = 100;
	int population = 10;
	boolean showOutput = true;
	int timeInMs = 1000*60;
	
	public LegislationDemo(){
		Log.add(this, "starting...");
        try {
		
			//settings
	        SettingsAdapter sa = SettingsAdapter.getInstance();
	        sa.setDefaultFolder(new File("C:\\Documents and Settings\\Pieter\\Mijn documenten\\_NETBEANS Projecten\\NMO-coverage_wireless_networks\\src"));
	        //sa.setDefaultFolder(new File("D:\\Documenten\\UGent\\NMO\\Coverage_for_wireless_networks\\src"));
	        //sa.setDefaultFolder(new File("C:\\Eclipse Env\\CWN\\src"));
				sa.addSettings(new File(sa.getDefault_folder(), "gsm.xml"));
	
	        //lynnes deel
			CoverageInterface ci = CoverageAdapter.getInstance();
			
			//Pieters deel
            PathlossInterface instanceOfPathlossInterface = PathLossAdapter.getInstance();
            LawInterface law = new Belgium(instanceOfPathlossInterface);

			LegislationInterface li = new LegislationAdapter(law , CoverageAdapter.getInstance());
			//LegislationInterface li = new LegislationDummy();
			
	
			//reading antennas

            AntennaSiteReader areader = new AntennaSiteReader();
            List<AntennaSite> list = areader.getAntennaSiteList(new File("C:\\Bipt antennes Brussels hoofdstedelijk gewest v2.shp"));
            Antenna[] antennas = areader.filterSiteListGUI(list);

			com.vividsolutions.jts.geom.GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
			WKTReader reader = new WKTReader( geometryFactory );
			
			area = (Polygon) reader.read("POLYGON ((143405.95458159476 168832.87821061225, 143730.35161200038 170879.07486393998, 144279.33120191758 171103.65742345157, 144454.00652598214 172501.06001596808, 143630.53714110635 172750.59619320318, 144204.47034874704 174098.09155027266, 145027.93973362286 173923.4162262081, 145302.42952858144 175894.7520263653, 146100.94529573375 175919.70564408883, 146749.73935654497 176793.08226441164, 149644.359012472 177217.2937657113, 149868.9415719836 176269.05629221795, 150542.68925051834 176244.10267449444, 151016.80798726503 177092.52567709374, 151391.11225311767 177217.2937657113, 151416.06587084115 178015.80953286358, 153212.7263469338 178415.06741643974, 153512.1697596159 177891.04144424605, 152663.7467570166 177541.69079611692, 153112.91187603978 176967.7575884762, 152688.70037474012 175869.7984086418, 152963.19016969873 175819.8911731948, 153661.891465957 176867.94311758218, 154260.77829132118 176867.94311758218, 154111.05658498014 176019.52011498285, 154585.1753217268 175395.67967189514, 154610.1289394503 173673.88004897302, 153013.09740514573 173025.08598816177, 152888.3293165282 172451.15278052108, 153786.65955457452 172900.31789954423, 154635.08255717382 172201.61660328598, 155483.50555977313 172401.24554507405, 155508.45917749664 171527.86892475124, 156756.1400636721 171577.77616019826, 156905.86177001314 168383.7130915891, 155558.36641294367 166412.37729143188, 156306.97494464894 165838.44408379117, 156930.81538773666 166038.07302557924, 158452.9860688707 164865.2529925743, 158452.9860688707 164341.2270203806, 157854.0992435065 164291.3197849336, 156406.78941554297 165239.55725842694, 156207.1604737549 165613.86152427958, 155283.87661798505 166187.7947319203, 153686.84508368047 165089.8355520859, 153661.891465957 164341.2270203806, 153836.56679002155 163368.03592916377, 154809.7578812384 163343.08231144026, 155807.90259017874 164241.4125494866, 156531.5575041605 163792.2474304634, 156306.97494464894 163068.59251648164, 155483.50555977313 163268.22145826972, 154061.1493495331 162594.47377973498, 153287.58720010435 163542.71125322834, 152663.7467570166 163941.9691368045, 152838.42208108117 164665.62405078625, 150892.03989864746 165014.97469891538, 150966.900751818 164216.45893176307, 151665.60204807625 164116.64446086905, 151565.78757718223 163318.12869371675, 150991.8543695415 162744.19548607603, 151316.25139994713 161945.67971892375, 150692.4109568594 161521.4682176241, 150318.10669100677 162569.52016201147, 149544.54454157798 162344.9376024999, 149170.24027572534 163168.4069873757, 148371.72450857307 162569.52016201147, 146300.5742375218 164416.08787355115, 146425.34232613936 164615.71681533923, 145651.78017671057 165663.7687597266, 145726.6410298811 166087.98026102624, 144678.58908549373 167011.26411679608, 143480.81543476527 166986.31049907257, 142682.299667613 166562.09899777293, 142432.7634903779 167086.12496996662, 142707.2532853365 167435.47561809575, 141983.59837135475 167909.5943548424, 142382.8562549309 168583.34203337715, 143106.51116891266 168233.99138524802, 143405.95458159476 168832.87821061225))");

			GeneticSearch gs = new GeneticSearch(antennas, area, ci, li, population);
			gs.runGeneticAlgorithm(generations, timeInMs);

			Log.add(this, "");
			Log.add(this, "");
			Log.add(this, "");
			Log.add(this, "Solution retrieved");
			Solution sol = gs.getSolutions().first();
			
			/*********** PIETER  ***********/
			li.getRadiationExceedingPoints(sol);
			li.printExceedingRadiationPoints();

	
			
			sol.mutateAll();
			Log.add(this, "Solution mutated");
			

			/*********** PIETER  ***********/
            li.getRadiationExceedingPoints(sol); //bereken
            li.printExceedingRadiationPoints();  //print ze uit (via console)
            li.writeRadiationPoints2shapefile(); // schrijf ze weg naar shape file

		
			
			
			
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
